using System;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace Norm.Helper
{
    public sealed class JavaScriptHelper
    {
        public static string WebServiceProxy(string webServiceUrl, string className, Hashtable methods)
        {
            StringBuilder sb = new StringBuilder();

            foreach (string method in methods.Keys)
            {
                string [] parameters = (string[])methods[method];
                sb.Append(className + ".prototype." + method + " = function(closure" +
                    (parameters.Length >0?",":"")+
                    string.Join(", ", parameters) + ")\n{\n");

                sb.Append("\tvar soapParams = new SOAPClientParameters();\n");

                foreach (string param in parameters)
                    sb.AppendFormat("\tsoapParams.add('{0}',{0});\n",param);

                sb.Append("\tSOAPClient.invoke('"+webServiceUrl+"','"+method+"',soapParams,true,closure);\n}\n\n");
            }

            return sb.ToString();
        }

        public static string ToJavaScriptObject(object o)
        {
            if (o == null)
                return "null";
            return "Implement ToJavaScriptObject";
        }
    }
}
